package main

import (
	"fmt"
	"net/http"
	"os"
	"strconv"
)

func main() {
	http.HandleFunc("/", allHandleFunc)
	http.HandleFunc("/healthz", healthzFunc)
	err := http.ListenAndServe(":"+strconv.Itoa(80), nil)
	if err != nil {
		fmt.Println("监听失败：", err.Error())
	}
}

func healthzFunc(writer http.ResponseWriter, request *http.Request) {
	writer.WriteHeader(200)
	fmt.Println(request.RemoteAddr, 200)
}

func allHandleFunc(w http.ResponseWriter, r *http.Request) {
	if len(r.Header) > 0 {
		for k, v := range r.Header {
			//fmt.Println(k+":",v,len(v))
			w.Header().Set(k, v[0])
		}
		gopath := os.Getenv("VERSION")
		fmt.Println(gopath)
		w.Header().Set("VERSION", gopath)

		fmt.Println(r.RemoteAddr, 200)
	}

}
